#include<stdio.h>
#define NOTFOUND -100

int binary_search(int a[],int key,int low,int high)
{
    int mid=low+(key-a[low])/(a[high]-a[low])*(high-low);
    while(low<=high)
    {
        if(a[mid]>key)          return binary_search(a,key,low,mid-1);
        else if (a[mid]<key)    return binary_search(a,key,mid+1,high);
        if(a[mid]==key)         return(mid);
    }
    return(NOTFOUND);
}

int main()
{
    int n,x,k;
    printf("请输入查找模型数据大小：");
    scanf("%d",&n);
    int database[n];
    printf("请输入查找模型数据样本：");
    for(int i=0;i<n;i++)
    {
        scanf("%d",&database[i]);
    }
    printf("请输入需要查找的数据:");
    scanf("%d",&x);
    k=binary_search(database,x,0,n-1);
    if(k!=100) printf("找到数据,位置为%d",k);
    else       printf("找不到数据%d",x);
}